﻿using SAEA.Common;
using KeydbCommand.Models;
using System;

namespace KeydbCommand.Libs
{
    /// <summary>
    /// keydb server info
    /// </summary>
    public static class ServerInfoDataHelper
    {
        /// <summary>
        /// GetInfo
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public static JsonResult<KeydbServerInfo> GetInfo(string name)
        {
            try
            {
                KeydbServerInfo keydbServerInfo = new KeydbServerInfo();

                keydbServerInfo.Cpu = CurrentKeydbClient.GetCpu(name).ToString("f2");

                keydbServerInfo.Memory= CurrentKeydbClient.GetUsedMem(name).ToString("f2");

                keydbServerInfo.Cmds = CurrentKeydbClient.GetOpsCmd(name).ToString();

                keydbServerInfo.Input = CurrentKeydbClient.GetInput(name).ToString("f2");

                keydbServerInfo.Output = CurrentKeydbClient.GetOutput(name).ToString("f2");

                return new JsonResult<KeydbServerInfo>() { Code = 1, Data = keydbServerInfo, Message = "OK" };
            }
            catch (Exception ex)
            {
                LogHelper.Error($"KeydbController.GetInfo name:{name}", ex);
                return new JsonResult<KeydbServerInfo>() { Code = 2, Message = ex.Message };
            }
        }
    }
}
